package org.hp.controller;

import com.github.pagehelper.PageInfo;
import org.hp.bean.Hosptial;
import org.hp.service.dictionary.HosptalService;
import org.hp.util.ResultJson;
import org.hp.util.ReturnJsonData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

@Controller
public class HosptalController {
    @Autowired
    HosptalService hosptalService;

    @RequestMapping("/queryHosp")
    @ResponseBody
    public void queryHosptal(HttpServletRequest req, HttpServletResponse resp,Integer page, Integer limit, String hname){
        List<Hosptial> list=hosptalService.queryHosp(limit,page,hname);
        PageInfo<Hosptial> hosptialPageInfo=new PageInfo<Hosptial>(list);
        ReturnJsonData.returnJson(ResultJson.success(hosptialPageInfo),resp);
    }

    @RequestMapping("/queryDelHosp")
    public void queryDelHosptal(HttpServletRequest req, HttpServletResponse resp,Integer page, Integer limit, String hname){
        List<Hosptial> list=hosptalService.queryDelHosp(limit,page,hname);
        PageInfo<Hosptial> hosptialPageInfo=new PageInfo<Hosptial>(list);
        ReturnJsonData.returnJson(ResultJson.success(hosptialPageInfo),resp);
    }

    @RequestMapping("/addHosp")
    public void addHosptal(HttpServletRequest req, HttpServletResponse resp,Hosptial h){
        int i=hosptalService.addHosp(h);
        ReturnJsonData.returnJson(i>0? ResultJson.success():ResultJson.error(),resp);
    }

    @RequestMapping("/queryOneHosp")
    public void queryOneHosptal(HttpServletRequest req, HttpServletResponse resp,Integer hid){
        Hosptial list=hosptalService.queryOneHosp(hid);
        System.out.println("查询一条"+list.toString());
        ReturnJsonData.returnJson(ResultJson.success(list),resp);
    }

    @RequestMapping("/updateHosp")
    public void updateHosptal(HttpServletRequest req, HttpServletResponse resp,Hosptial h){
        int i=hosptalService.updateHosp(h);
        ReturnJsonData.returnJson(i>0? ResultJson.success():ResultJson.error(),resp);
    }

    @RequestMapping("/delHosp")
    public void delHosptal(HttpServletRequest req, HttpServletResponse resp){
        Integer hid=Integer.valueOf(req.getParameter("hid"));
        int i=hosptalService.delHosp(hid);
        ReturnJsonData.returnJson(i>0? ResultJson.success():ResultJson.error(),resp);
    }

    @RequestMapping("/returnHosp")
    public void returnHosptal(HttpServletRequest req, HttpServletResponse resp){
        Integer hid=Integer.valueOf(req.getParameter("hid"));
        int i=hosptalService.returnHosp(hid);
        ReturnJsonData.returnJson(i>0? ResultJson.success():ResultJson.error(),resp);
    }


}
